class FileCache

  def initialize(cache_path)
    @cache_path = cache_path
    @cache_value = nil
  end

  def get
    return cache_value
  end

  def set(value)
    File.open(@cache_path, "w") do |f|
      f.write(value)
    end
  end

  def has_value?
    return !cache_value.nil?
  end

  private

  def cache_value
    unless @cache_value
      generate_cache_if_none
      @cache_value = File.readlines(@cache_path).first.gsub(/\n/, "")
    end
    return @cache_value
  end

  def generate_cache_if_none
    unless File.exists?(@cache_path)
      File.open(@cache_path, "w")
    end
  end
end
